import get from '@dfeidao/atom-web/local/get';
import remove from '@dfeidao/atom-web/local/remove';
import set from '@dfeidao/atom-web/local/set';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import set_node_cls from '@dfeidao/atom-web/ui/set-node-cls';
import { IFeidaoAiBrowserComponent } from '@dfeidao/web/interfaces';
import hide_loading from '../../atom/hide-loading';
import show_loading from '../../atom/show-loading';
import P02 from './P02';
import P03 from './P03';
import P06 from './P06';
export default async function a021(fd: IFeidaoAiBrowserComponent, args: { role_allot_id: string; str: string; _id: string; ids: string[] }) {
	//  调用事件
	//  group_id, role_allot_id, id
	const role_allot_id = args.role_allot_id;
	set(fd, 'role_allot_id', role_allot_id);
	const productid = get(fd, 'productid');
	const query = { productid, role_allot_id };
	remove(fd, 'allot_group');
	show_loading();
	const data = await nodejs<{ length: number }>('roler/service/allot_conditions_group_find', query);
	hide_loading();
	if (data.length === 0) {
		render(fd, '', P02, 'P02', 'inner');
	} else {
		render(fd, data, P02, 'P02', 'inner');
		// if (args.str) {
		if (args.str === 'hebing') {
			render(fd, '', P06, 'P06', 'inner');
			render(fd, '', P03, 'P03', 'inner');
		} else if (args._id) {
			const id = args._id;
			const items = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-id2="' + id + '"]');
			set_node_cls(items, 'bg-c', true);
			const _id = items.getAttribute('data-feidao-id2');
			const connector = items.getAttribute('data-feidao-connector');
			const group_id = items.getAttribute('data-feidao-group_id');
			const group = items.getAttribute('data-feidao-group');
			set(fd, 'allot_group', {
				id: _id, connector, group_id, group
			});
		}
		// }
		if (args.ids) {
			if (args.ids.length !== 0) {
				args.ids.map((v: string) => {
					if (v) {
						fd.data.node.querySelector<HTMLInputElement>('[data-feidao-id4="' + v + '"]').checked = true;
					}
				});
			}
		}
	}
}
